﻿namespace Cik.Gapi4net.Testing.Infrastructure
{
    using Gapi4Net.Core.AcsynRequest;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    internal class DownloaderTesting
    {
        private IDownloader _downloader;
        private const string WebSearchUrl = @"http://ajax.googleapis.com/ajax/services/search/web?v={0}&q={1}";
        private readonly string _realUrl;

        public DownloaderTesting()
        {
            _downloader = new Downloader();
            _realUrl = string.Format(WebSearchUrl, "1.0", "Google");
        }

        [TestInitialize]
        public void InitTesting()
        {
        }

        [TestCleanup]
        public void EndTesting()
        {
            _downloader.Dispose();
        }

        [TestMethod]
        public void Can_Add_Url_To_List()
        {
            _downloader.Add(_realUrl);
            Assert.IsTrue(_downloader.Count == 1);
        }

        [TestMethod]
        public void Can_Execute_Download_Link()
        {
            _downloader.Add(_realUrl);
            _downloader.DownloadAll(Process).ExecuteAndWait();
        }

        public void Process(Async<string> html)
        {
            var result = html.Result;
        }
    }
}